using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace ASPNETVN.PORTAL.Modules.DVDZone.Components
{
	public partial class Movie
	{
		#region Private members.
		
		protected int _ID;
		protected int _CategoryID;
		protected string _Title = string.Empty;
		protected string _ImagePath = string.Empty;
		protected string _Director = string.Empty;
		protected string _Cast = string.Empty;
		protected string _Studio = string.Empty;
		protected int _TheatricalRelease;
		protected string _Language = string.Empty;
		protected string _Caption = string.Empty;
		protected string _Duration = string.Empty;
		protected string _Memo = string.Empty;
		protected string _CreatedBy = string.Empty;
		protected DateTime _CreatedDate;
		protected string _LastUpdatedBy = string.Empty;
		protected DateTime _LastUpdatedDate;
		protected string _ApprovedBy = string.Empty;
		protected DateTime _ApprovedDate;

		#endregion
		
		//---------------------------------------------------------------------------------------------

		#region Properties.
		
		public int ID
		{
			set {this._ID = value;}
			get {return this._ID;}
		}
		
		public int CategoryID
		{
			set {this._CategoryID = value;}
			get {return this._CategoryID;}
		}
		
		public string Title
		{
			set {this._Title = value;}
			get {return this._Title;}
		}
		
		public string ImagePath
		{
			set {this._ImagePath = value;}
			get {return this._ImagePath;}
		}
		
		public string Director
		{
			set {this._Director = value;}
			get {return this._Director;}
		}
		
		public string Cast
		{
			set {this._Cast = value;}
			get {return this._Cast;}
		}
		
		public string Studio
		{
			set {this._Studio = value;}
			get {return this._Studio;}
		}
		
		public int TheatricalRelease
		{
			set {this._TheatricalRelease = value;}
			get {return this._TheatricalRelease;}
		}
		
		public string Language
		{
			set {this._Language = value;}
			get {return this._Language;}
		}
		
		public string Caption
		{
			set {this._Caption = value;}
			get {return this._Caption;}
		}
		
		public string Duration
		{
			set {this._Duration = value;}
			get {return this._Duration;}
		}
		
		public string Memo
		{
			set {this._Memo = value;}
			get {return this._Memo;}
		}
		
		public string CreatedBy
		{
			set {this._CreatedBy = value;}
			get {return this._CreatedBy;}
		}
		
		public DateTime CreatedDate
		{
			set {this._CreatedDate = value;}
			get {return this._CreatedDate;}
		}
		
		public string LastUpdatedBy
		{
			set {this._LastUpdatedBy = value;}
			get {return this._LastUpdatedBy;}
		}
		
		public DateTime LastUpdatedDate
		{
			set {this._LastUpdatedDate = value;}
			get {return this._LastUpdatedDate;}
		}
		
		public string ApprovedBy
		{
			set {this._ApprovedBy = value;}
			get {return this._ApprovedBy;}
		}
		
		public DateTime ApprovedDate
		{
			set {this._ApprovedDate = value;}
			get {return this._ApprovedDate;}
		}
		
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static Movie Load(int iD)
		{
			const string spName = "[dbo].[p_DVDZONE_Movie_Load]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, iD);
			Movie entity = null;
            IDataReader reader = db.ExecuteReader(dbCommand);
			if (reader.Read())
			{
				entity = new Movie();
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("CategoryID"))) entity.CategoryID = reader.GetInt32(reader.GetOrdinal("CategoryID"));
				if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
				if (!reader.IsDBNull(reader.GetOrdinal("ImagePath"))) entity.ImagePath = reader.GetString(reader.GetOrdinal("ImagePath"));
				if (!reader.IsDBNull(reader.GetOrdinal("Director"))) entity.Director = reader.GetString(reader.GetOrdinal("Director"));
				if (!reader.IsDBNull(reader.GetOrdinal("Cast"))) entity.Cast = reader.GetString(reader.GetOrdinal("Cast"));
				if (!reader.IsDBNull(reader.GetOrdinal("Studio"))) entity.Studio = reader.GetString(reader.GetOrdinal("Studio"));
				if (!reader.IsDBNull(reader.GetOrdinal("TheatricalRelease"))) entity.TheatricalRelease = reader.GetInt32(reader.GetOrdinal("TheatricalRelease"));
				if (!reader.IsDBNull(reader.GetOrdinal("Language"))) entity.Language = reader.GetString(reader.GetOrdinal("Language"));
				if (!reader.IsDBNull(reader.GetOrdinal("Caption"))) entity.Caption = reader.GetString(reader.GetOrdinal("Caption"));
				if (!reader.IsDBNull(reader.GetOrdinal("Duration"))) entity.Duration = reader.GetString(reader.GetOrdinal("Duration"));
				if (!reader.IsDBNull(reader.GetOrdinal("Memo"))) entity.Memo = reader.GetString(reader.GetOrdinal("Memo"));
				if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
				if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
				if (!reader.IsDBNull(reader.GetOrdinal("LastUpdatedBy"))) entity.LastUpdatedBy = reader.GetString(reader.GetOrdinal("LastUpdatedBy"));
				if (!reader.IsDBNull(reader.GetOrdinal("LastUpdatedDate"))) entity.LastUpdatedDate = reader.GetDateTime(reader.GetOrdinal("LastUpdatedDate"));
				if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
				if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
			}
			reader.Close();
			dbCommand.Connection.Close();
			
			return entity;
		}		
		
		//---------------------------------------------------------------------------------------------
		

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_DVDZONE_Movie_SelectAll]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------

		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_DVDZONE_Movie_SelectAll]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_DVDZONE_Movie_SelectDynamic]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------

		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_DVDZONE_Movie_SelectDynamic]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static int Insert(int categoryID, string title, string imagePath, string director, string cast, string studio, int theatricalRelease, string language, string caption, string duration, string memo, string createdBy, DateTime createdDate, string lastUpdatedBy, DateTime lastUpdatedDate, string approvedBy, DateTime approvedDate)
		{
			Movie entity = new Movie();			
			entity.CategoryID = categoryID;
			entity.Title = title;
			entity.ImagePath = imagePath;
			entity.Director = director;
			entity.Cast = cast;
			entity.Studio = studio;
			entity.TheatricalRelease = theatricalRelease;
			entity.Language = language;
			entity.Caption = caption;
			entity.Duration = duration;
			entity.Memo = memo;
			entity.CreatedBy = createdBy;
			entity.CreatedDate = createdDate;
			entity.LastUpdatedBy = lastUpdatedBy;
			entity.LastUpdatedDate = lastUpdatedDate;
			entity.ApprovedBy = approvedBy;
			entity.ApprovedDate = approvedDate;
			return entity.Insert();
		}
		
		public int Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public int Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_DVDZONE_Movie_Insert]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddOutParameter(dbCommand, "@ID", SqlDbType.Int, 4);
			db.AddInParameter(dbCommand, "@CategoryID", SqlDbType.Int, this._CategoryID);
			db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, this._Title);
			db.AddInParameter(dbCommand, "@ImagePath", SqlDbType.NVarChar, this._ImagePath);
			db.AddInParameter(dbCommand, "@Director", SqlDbType.NVarChar, this._Director);
			db.AddInParameter(dbCommand, "@Cast", SqlDbType.NVarChar, this._Cast);
			db.AddInParameter(dbCommand, "@Studio", SqlDbType.NVarChar, this._Studio);
			db.AddInParameter(dbCommand, "@TheatricalRelease", SqlDbType.Int, this._TheatricalRelease);
			db.AddInParameter(dbCommand, "@Language", SqlDbType.NVarChar, this._Language);
			db.AddInParameter(dbCommand, "@Caption", SqlDbType.NVarChar, this._Caption);
			db.AddInParameter(dbCommand, "@Duration", SqlDbType.Char, this._Duration);
			db.AddInParameter(dbCommand, "@Memo", SqlDbType.NText, this._Memo);
			db.AddInParameter(dbCommand, "@CreatedBy", SqlDbType.VarChar, this._CreatedBy);
			db.AddInParameter(dbCommand, "@CreatedDate", SqlDbType.DateTime, this._CreatedDate);
			db.AddInParameter(dbCommand, "@LastUpdatedBy", SqlDbType.VarChar, this._LastUpdatedBy);
			db.AddInParameter(dbCommand, "@LastUpdatedDate", SqlDbType.DateTime, this._LastUpdatedDate);
			db.AddInParameter(dbCommand, "@ApprovedBy", SqlDbType.VarChar, this._ApprovedBy);
			db.AddInParameter(dbCommand, "@ApprovedDate", SqlDbType.DateTime, this._ApprovedDate);
			
			if (transaction != null)
			{
				db.ExecuteNonQuery(dbCommand, transaction);
				this._ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return this._ID;
			}
            else
			{
				db.ExecuteNonQuery(dbCommand);
				this._ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return this._ID;
			}			
		}
		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int Update(int iD, int categoryID, string title, string imagePath, string director, string cast, string studio, int theatricalRelease, string language, string caption, string duration, string memo, string createdBy, DateTime createdDate, string lastUpdatedBy, DateTime lastUpdatedDate, string approvedBy, DateTime approvedDate)
		{
			Movie entity = new Movie();			
			entity.ID = iD;
			entity.CategoryID = categoryID;
			entity.Title = title;
			entity.ImagePath = imagePath;
			entity.Director = director;
			entity.Cast = cast;
			entity.Studio = studio;
			entity.TheatricalRelease = theatricalRelease;
			entity.Language = language;
			entity.Caption = caption;
			entity.Duration = duration;
			entity.Memo = memo;
			entity.CreatedBy = createdBy;
			entity.CreatedDate = createdDate;
			entity.LastUpdatedBy = lastUpdatedBy;
			entity.LastUpdatedDate = lastUpdatedDate;
			entity.ApprovedBy = approvedBy;
			entity.ApprovedDate = approvedDate;
			return entity.Update();
		}
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_DVDZONE_Movie_Update]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, this._ID);
			db.AddInParameter(dbCommand, "@CategoryID", SqlDbType.Int, this._CategoryID);
			db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, this._Title);
			db.AddInParameter(dbCommand, "@ImagePath", SqlDbType.NVarChar, this._ImagePath);
			db.AddInParameter(dbCommand, "@Director", SqlDbType.NVarChar, this._Director);
			db.AddInParameter(dbCommand, "@Cast", SqlDbType.NVarChar, this._Cast);
			db.AddInParameter(dbCommand, "@Studio", SqlDbType.NVarChar, this._Studio);
			db.AddInParameter(dbCommand, "@TheatricalRelease", SqlDbType.Int, this._TheatricalRelease);
			db.AddInParameter(dbCommand, "@Language", SqlDbType.NVarChar, this._Language);
			db.AddInParameter(dbCommand, "@Caption", SqlDbType.NVarChar, this._Caption);
			db.AddInParameter(dbCommand, "@Duration", SqlDbType.Char, this._Duration);
			db.AddInParameter(dbCommand, "@Memo", SqlDbType.NText, this._Memo);
			db.AddInParameter(dbCommand, "@CreatedBy", SqlDbType.VarChar, this._CreatedBy);
			db.AddInParameter(dbCommand, "@CreatedDate", SqlDbType.DateTime, this._CreatedDate);
			db.AddInParameter(dbCommand, "@LastUpdatedBy", SqlDbType.VarChar, this._LastUpdatedBy);
			db.AddInParameter(dbCommand, "@LastUpdatedDate", SqlDbType.DateTime, this._LastUpdatedDate);
			db.AddInParameter(dbCommand, "@ApprovedBy", SqlDbType.VarChar, this._ApprovedBy);
			db.AddInParameter(dbCommand, "@ApprovedDate", SqlDbType.DateTime, this._ApprovedDate);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int Delete(int iD)
		{
			Movie entity = new Movie();
			entity.ID = iD;
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_DVDZONE_Movie_Delete]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, this._ID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		#endregion
	}	
}